<?php
namespace Admin\Controller;
use Think\Controller;
use Think\Verify;
class LoginController extends CommonController {
    public function index(){
	if(empty($_POST)){
                $webname = new \Admin\Model\SysinfoModel(sys_info);
		$info = $webname -> getSysInfo();
                $this->assign('webname',$info);
                $this->display();
        
        }else{
                 $login = new \Admin\Model\LoginModel(admin);
                 $info = $login -> logincheck();
                  $codes = new \Think\Verify();
                if($codes ->check($_POST['code'])){
                    
                }else{
                    $this->error('验证码错误，请检查您的验证码');
                }
                 if($info == -2){
                 $this->error('该用户名不存在，请检查后再登陆');
                 }
                  if($info == -1){
                 	$this->error('密码错误，请检查您的密码');
                 }
                 else{
                     $_SESSION['admin'] = $_POST['adname'];
                     $_SESSION['adid'] = $info;
                    $this->success('登陆成功',U("Admin/Index/index"));
                 }
        }
    }
    function codes(){
        $cfg = array(
            'imageH' =>40,
            'imageW' =>140,
            'fontSize' => 20,
            'length' => 4,
            'fonttf' => '4.ttf',
            'useCurve' => true,
            'useNoise' => false,
        );
        $code = new Verify($cfg);
		ob_clean();
        $code->entry();
    }
    
    function logout(){
        session_destroy();
        $this->success('退出成功','index');
    }
	
}